#pragma once
#include <memory>
#include <set>
#include "Channel.h"
#include "XnccType.h"

namespace xncc {
namespace foundation {
    class UdpSocket;
    class XnccAddress;
    class DatagramAcceptChannel final : public Channel
    {
      public:
        DatagramAcceptChannel(EventLoop*                   loop,
                              std::shared_ptr<UdpSocket>   serverSocket,
                              const std::set<std::string>& blacklist);
        ~DatagramAcceptChannel() override;

        DatagramAcceptChannel(const DatagramAcceptChannel&)             = delete;
        DatagramAcceptChannel(const DatagramAcceptChannel&&)            = delete;
        DatagramAcceptChannel& operator=(const DatagramAcceptChannel&)  = delete;
        DatagramAcceptChannel& operator=(const DatagramAcceptChannel&&) = delete;

        auto Type() -> ChannelType::value override { return ChannelType::DGRAM_ACCEPT_CHANNEL; }
        void handleRead() override;
        void handleWrite() override;

        void setNewConnCallback(
            const std::function<void(int sockfd, types::connection_id_t connId, std::shared_ptr<XnccAddress>)> cb)
        {
            newConnectionCallback_ = cb;
        }

      private:  // 列表初始化
        const uint32_t HEADER_LEN;
        std::function<void(int sockfd, types::connection_id_t connId, std::shared_ptr<XnccAddress>)>
                                   newConnectionCallback_;
        std::shared_ptr<UdpSocket> serverSocket_;
        std::set<std::string>      blacklist_;
    };
}  // namespace foundation
}  // namespace xncc